package com.thunisoft.refactoring.chapter6;

/**
 * @ClassName ExtractFunction
 * @Description 提炼函数
 * @Author wangkeyuan
 * @Date 2019-06-09 23:49
 * @Version 1.0
 */
public class ExtractFunction {

    public static void main(String[] args) {

        // 重构前
        Invoice invoice = new Invoice();
        beforePrintOwing(invoice);

        // 重构后
        afterPrintOwing(invoice);
    }

    /**
     * 重构后
     * @param invoice
     */
    private static void afterPrintOwing(Invoice invoice) {
        printBanner();
        Long outstanding = calculateOutStanding();

        // printDetail
//        System.out.println("name:"+invoice.customer);
//        System.out.println("amount:"+outstanding);

        printDetail(invoice,outstanding);
    }

    private static void printDetail(Invoice invoice,Long outstanding) {
        System.out.println("name:"+invoice.customer);
        System.out.println("amount:"+outstanding);
    }

    /**
     * 重构前
     * @param invoice
     */
    private static void beforePrintOwing(Invoice invoice){
        printBanner();
        Long outstanding = calculateOutStanding();

        // printDetail
        System.out.println("name:"+invoice.customer);
        System.out.println("amount:"+outstanding);
    }








    private static Long calculateOutStanding() {
        return 0L;
    }

    private static void printBanner() {
    }

    static class Invoice{

        private String customer;


    }
}
